package leetcode.题库.数组.普通数组;

import java.util.HashSet;
import java.util.Set;

/**
 * 最长连续序列
 *
 * @author yanzhenming
 * @date 2023/4/19  15:20
 */
public class Solution128 {
    public int longestConsecutive(int[] nums) {
        int res = 0;
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        for(int num : nums){
            if (set.contains(num-1)){
                continue;
            }
            int temp = 0;
            while(set.contains(num)) {
                num++;
                temp++;
            }
            res = Math.max(temp, res);
        }
        return res;
    }
}
